/**
 * @author: zxb
 * @date: 2024-11-22
 * @des : This file is used to define the router of news. 新闻
 * @router: /news/add
 **/

const Router = require('koa-router');

const { upload, addNews, getNewsList, updateNews, deleteNews, getNewsDetail } = require('../controller/news.controller')
const { validateNews, PageSizeOrPage } = require('../middleware/news.middleware')
const { auth, hasAdminPermission } = require('../middleware/auth.middleware') // 判断是否含有token，以及是否有管理员权限验证

const router = new Router({ prefix: '/news' });

router.post('/upload', auth, hasAdminPermission, upload); //上传新闻图片封面
router.post('/add', auth, hasAdminPermission, validateNews, addNews); // 添加新闻
router.post('/update', auth, hasAdminPermission, updateNews); // 更新新闻
router.post('/delete', auth, hasAdminPermission, deleteNews); // 删除新闻
router.post('/detail', getNewsDetail); // 获取新闻详情
router.post('/list', PageSizeOrPage, getNewsList); // 获取新闻列表

module.exports = router; // 导出router